//
//  CDCuriosityViewCell.m
//  CuriosityDaily3
//
//  Created by panzhi on 16/9/25.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "CDCuriosityViewCell.h"
#import "UIImageView+WebCache.h"

@interface CDCuriosityViewCell ()

@property(nonatomic,weak)UIImageView *imageview;
@property(nonatomic,weak)UILabel *titlelabel;
@property(nonatomic,weak)UILabel *desclabel;

@end

@implementation CDCuriosityViewCell

- (void)awakeFromNib {
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    UIImageView *imageview = [[UIImageView alloc]init];
    [self.contentView addSubview:imageview];
    
    UILabel *titlelabel =[[UILabel alloc]init];
    [titlelabel sizeToFit];
    titlelabel.numberOfLines = 2;
    [self.contentView addSubview:titlelabel];

    UILabel *desclabel = [[UILabel alloc]init];
    [desclabel setFont:[UIFont systemFontOfSize:15]];
    [desclabel sizeToFit];
    desclabel.numberOfLines = 0;
    [desclabel setTextColor:[UIColor darkGrayColor]];
    [self.contentView addSubview:desclabel];
    
    self.imageview = imageview;
    self.titlelabel = titlelabel;
    self.desclabel = desclabel;
    
    [self.imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.height.offset(150);
    }];
    
    [self.titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageview.mas_bottom).offset(8);
        make.left.offset(10);
        make.right.offset(-10);
    }];
    
    [self.desclabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titlelabel.mas_bottom).offset(8);
        make.left.equalTo(self.titlelabel);
        make.right.equalTo(self.titlelabel);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
    

}

-(void)setModel:(CDCuriosityModel *)model{
    _model = model;
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:model.image]];
    self.titlelabel.text = model.title;
    self.desclabel.text = model.desc;
}

@end
